import builtins


def print(is_cli, *args):
    if not isinstance(is_cli, bool):
        raise Exception('1st argument must be bool to indicate printing to gui or cli')

    try:
        # (bool,dummy_st,text)
        if is_cli:
            builtins.print(args[1])
        else:
            st, text = args
            st.insert('1.0', str(text) + '\n')
    except Exception as e:
        builtins.print(e)


if __name__ == '__main__':
    print(True, 'command line')
    from tkinter import *
    import tkinter.scrolledtext as tkst

    tk = Tk()
    st = tkst.ScrolledText(master=tk, width=30, height=10)
    st.grid(row=0, column=0, rowspan=2, columnspan=2, pady=10)
    print(False, st, 'this should be printed in a window')
    tk.mainloop()
